package com.xueyi.workflow.controller;

import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.common.security.auth.pool.WorkflowPool;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.workflow.domain.dto.FormDefineDto;
import com.xueyi.workflow.domain.query.FormDefineQuery;
import com.xueyi.workflow.service.FormDefineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@Tag(name = "表单定义管理")
@RestController
@RequestMapping("/form")
public class FormDefineController extends BaseController<FormDefineQuery, FormDefineDto, FormDefineService> {
    @Autowired
    private FormDefineService baseService;

    @Override
    protected String getNodeName() {
        return "表单";
    }

    @Operation(summary = "分页查询表单定义")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_LIST + "')")
    @GetMapping("/list")
    public AjaxResult list(FormDefineQuery query) {
        return super.list(query);
    }

    @Operation(summary = "查询表单定义详情")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_SINGLE + "')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    @Operation(summary = "新增表单定义")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_ADD + "')")
    @PostMapping
    public AjaxResult add(@Validated({V_A.class}) @RequestBody FormDefineDto dto) {
        return super.add(dto);
    }

    @Operation(summary = "修改表单定义")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_EDIT + "')")
    @PutMapping
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody FormDefineDto dto) {
        return super.edit(dto);
    }

    @Operation(summary = "批量删除表单定义")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_DEL + "')")
    @DeleteMapping("/batch/{idList}")
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }

    @Operation(summary = "发布为公共数据")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_FORM_PUBLISH_PUBLIC + "')")
    @PostMapping("/publishPublic/{id}")
    public AjaxResult publishPublic(@PathVariable Long id) {
        return baseService.publishPublic(id);
    }
}
